import { RedisConfig } from "../../config/RedisConfig";
import { Logger } from "./Logger";
import { RedisClient } from "./RedisClient";

export class RedisManager {

    public static instance: RedisManager = new RedisManager();

    public redisClientList: Array<RedisClient> = [];

    public init() {
        for (const key in RedisConfig.Database_Index) {
            if (RedisConfig.Database_Index.hasOwnProperty(key)) {
                const element = RedisConfig.Database_Index[key];
                let redisClient: RedisClient = new RedisClient();
                redisClient.init(element);
                this.redisClientList.push(redisClient);
            }
        }
    }

    public getRedis(database: number) {
        for (let i = 0; i < this.redisClientList.length; i++) {
            let redis: RedisClient = this.redisClientList[i];
            if (redis.databaseIndex == database) {
                return redis;
            }
        }
        Logger.error("getRedis error==", database);
    }

}